package com.wechat.process.message;

import com.wechat.constants.WechatConstants;
import com.wechat.pojo.WechatMessage;
import com.wechat.pojo.WechatTextMessage;
import com.wechat.utils.XmlUtils;
import lombok.Getter;
import lombok.Setter;

import java.io.PrintWriter;

/**
 * Created by why on 2018/2/26 0026.
 */
public class WechatTextMessageProcess implements WechatMessageProcessInterface {


    @Setter
    private String openId;

    @Setter
    private String responseText;

    @Override
    public void autoReplyWechatMessage(PrintWriter wechatWriter) {
        String msg = getWechatTextMessage(responseText);
        wechatWriter.write(msg);
    }

    public String getWechatTextMessage(String responseText) {
        WechatMessage wechatMessage = getWechatMessage(openId);
        WechatTextMessage wechatTextMessage = new WechatTextMessage(wechatMessage.getToUserName(), wechatMessage.getFromUserName(),
                wechatMessage.getCreateTime(), WechatConstants.XmlMsgType.TEXT, responseText);
        String textMessage = XmlUtils.objectConvertToXml(wechatTextMessage);
        return textMessage;
    }

}
